/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

class Solution
{
public:

    vector<vector<int>> levelOrder(TreeNode* root)
    {
        if (root == NULL)
            return {};
        vector<vector<int>> arr;

        queue<TreeNode*> q;

        q.push(root);

        while (!q.empty())
        {
            int size = q.size();
            vector<int> brr;
            for (int j = 0; j < size; j++)
            {
                TreeNode* tmp = q.front();
                q.pop();
                brr.push_back(tmp->val);
                if (tmp->left)
                    q.push(tmp->left);
                if (tmp->right)
                    q.push(tmp->right);
            }
            arr.push_back(brr);
        }

        return arr;
    }
};